package com.gzh.controller;


import com.gzh.entity.Stu;
import com.gzh.service.IStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李浩然
 * @since 2022-05-23
 */
@RestController
@RequestMapping("/stu")
public class StuController {

    @Autowired
    IStuService iStuService;

    @RequestMapping("getlist")
     public List<Stu>  getlist(){
        List<Stu> list = iStuService.list();
        return list;
    }

    @RequestMapping("toadd")
    public int toaddstu(@RequestBody Stu stu){
        boolean b = iStuService.save(stu);
        if(b){
            return 1;
        }else {
            return 0;
        }

    }
    @RequestMapping("todel")
    public int todel(Integer id){
        boolean b = iStuService.removeById(id);
        if(b){
            return 1;
        }else {
            return 0;
        }

    }

    @RequestMapping("echo")
    public Stu echo(Integer id){
        Stu stu = iStuService.getById(id);
        return stu;

    }

    @RequestMapping("toupstu")
    public int  toupstu(@RequestBody Stu stu){
        boolean b = iStuService.updateById(stu);
        if(b){
            return 1;
        }else {
            return 0;
        }
    }

}
